﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.Debugging {

	/// <summary>
	/// Log history line object
	/// </summary>
	public class LogHistoryLine {
		private int _padding;
		private Severity _severity;
		private string _value;

		public LogHistoryLine(int padding, Severity severity, string value) {
			_padding = padding;
			_severity = severity;
			_value = value;
		}

		/// <summary>
		/// Gets the padding of line.
		/// </summary>
		/// <value>The padding of line.</value>
		public int Padding {
			get { return _padding; }
		}

		/// <summary>
		/// Gets the severity of this line.
		/// </summary>
		/// <value>The severity of this line.</value>
		public Severity Severity {
			get { return _severity; }
		}

		/// <summary>
		/// Gets the string value of line.
		/// </summary>
		/// <value>The string value of line.</value>
		public string Value {
			get { return _value; }
		}
	}

	/// <summary>
	/// Log history object. It holds some amount of log history lines for displaying them in console.
	/// </summary>
	public class LogHistory {
		private char[] SEPARATOR = new char[] { '\n' };

		///<summary>Log lines</summary>
		List<LogHistoryLine> _lines = new List<LogHistoryLine>();

		/// <summary>
		/// Adds the message into history.
		/// </summary>
		/// <param name="paddingLevel">The padding level.</param>
		/// <param name="messageSeverity">The message severity.</param>
		/// <param name="message">The message.</param>
		public void AddMessage(int paddingLevel, Severity messageSeverity, string message) {
			message = message.Replace("\t", "    ");
			foreach (string line in message.Split(SEPARATOR)) {
				_lines.Add(new LogHistoryLine(paddingLevel, messageSeverity, line));
			}
		}

		/// <summary>
		/// Gets the line count in history.
		/// </summary>
		/// <value>The line count.</value>
		public int LineCount {
			get { return _lines.Count; }
		}

		/// <summary>
		/// Gets the <see cref="Vortex.Debugging.LogHistoryLine"/> for the specified line number.
		/// </summary>
		/// <value>Log history line</value>
		public LogHistoryLine this[int lineNumber] {
			get { return _lines[lineNumber]; }
		}

	}
}
